<style type="text/css">
.CodeMirror-line-numbers {
    width: 2.2em;
    color: #aaa;
    background-color: #eee;
    text-align: right;
    padding-right: .3em;
    font-size: 10pt;
    font-family: monospace;
    padding-top: .4em;
    line-height: normal;
}
</style>

<div class="form wide">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'text-form',
	'enableAjaxValidation'=>false,
)); ?>

	<?php echo $form->errorSummary($model); ?>

    <?php if (! $model->IsNewRecord) echo $form->hiddenField($model, "id") ; ?>
    <?php $this->beginClip('content');?>
        <div class="row" style="border: 1px solid #000;">
            <?php echo $form->textArea($model,'content',array('cols'=>70, 'rows'=>7, 'encode'=>true)); ?>
            <?php echo $form->error($model,'content'); ?>
        </div>
    <?php $this->endClip();?>
    
    <?php $this->beginClip('css');?>
        <div class="row" style="border: 1px solid #000;">
            <?php echo $form->textArea($model,'css',array('cols'=>70, 'rows'=>7, 'encode'=>true)); ?>
            <?php echo $form->error($model,'css'); ?>
        </div>
    <?php $this->endClip();?>
    
    <?php $this->beginClip('widgetSettings');?>
    <h3>Widget Settings</h3>
    <?php
if(!empty($formParams->elements)){
    $group = '';
    foreach($formParams->elements as $name => $elm) {
        if ($group != $elm->param->setting_group) {
            $group = $elm->param->setting_group;
            echo "<div class=\"form-group-heading\">{$group}</div>";
        }
        echo $elm->render();
    }
}
?>
<?php $this->endClip(); ?>
    
    <?php $this->beginClip('widgetLayoutSettings');?>
    <h3>Widget Layout Settings</h3>
    <?php
if(!empty($formLayoutParams->elements)){
    $group = '';
    foreach($formLayoutParams->elements as $name => $elm) {
        if ($group != $elm->param->setting_group) {
            $group = $elm->param->setting_group;
            echo "<div class=\"form-group-heading\">{$group}</div>";
        }
        echo $elm->render();
    }
}
?>
<?php $this->endClip(); ?>
    
    <?php
    $tabs = array(
        'Content'   => $this->Clips['content'],
        'Style'     => $this->Clips['css'],
        'Widget Settings' => $this->Clips['widgetSettings'],
        'Widget Layout Settings' => $this->Clips['widgetLayoutSettings'],
    );?>
    
    <?php
    $this->widget('zii.widgets.jui.CJuiTabs', array(
        'id'=>'page-tabs',
        'tabs'=>$tabs,
        'options'=>array(
            'cache'=>true,
        )
    ));
    ?> 

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->
<?php
$cs = Yii::app()->clientScript;

$cs->registerScript('WidgetChangeLayout', "
$('#currentLayout').change(function(){
    $('#view').val('view');
    $(this).closest('form').
        append('<input type=\"hidden\" name=\"continue\" value=\"1\" />')
        .get(0).submit();
});
");

$cs->registerScriptFile(Yii::app()->theme->baseUrl.'/scripts/CodeMirror/js/codemirror.js');

$script = "
var content_editor = CodeMirror.fromTextArea('".CHtml::getActiveId($model, 'content')."', {
    height: '350px',
    parserfile: 'parsexml.js',
    stylesheet: '".Yii::app()->theme->baseUrl."/scripts/CodeMirror/css/xmlcolors.css',
    path: '".Yii::app()->theme->baseUrl."/scripts/CodeMirror/js/',
    continuousScanning: 500,
    lineNumbers: true
});

var css_editor = CodeMirror.fromTextArea('".CHtml::getActiveId($model, 'css')."', {
    height: '350px',
    parserfile: 'parsecss.js',
    stylesheet: '".Yii::app()->theme->baseUrl."/scripts/CodeMirror/css/csscolors.css',
    path: '".Yii::app()->theme->baseUrl."/scripts/CodeMirror/js/',
    continuousScanning: 500,
    lineNumbers: true
});
";
$cs->registerScript(__CLASS__.'#InitXMLEditor', $script);

?>